package study.springcloud.config.nacos.controller;

import com.alibaba.druid.pool.DruidDataSource;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import study.springcloud.config.nacos.mapper.UserBaseEO;
import study.springcloud.config.nacos.mapper.UserBaseMapper;
import study.eggs.result.Result;
import study.eggs.result.Results;

import java.util.Map;

@Slf4j
@RestController
public class _4_DsController {

    @Autowired
    private DruidDataSource dataSource;
    @Autowired
    private UserBaseMapper userBaseMapper;

    @RequestMapping("/datasource/info")
    public Result datasource() {
        //
        String url = dataSource.getUrl();
        //
        Map<String, Object> data = Maps.newHashMap();
        data.put("url", url);
        return Results.ok(data);
    }

    @RequestMapping("/mybatis/get")
    public Result get() {
        UserBaseEO ubEO = userBaseMapper.get(1L);
        return Results.ok(ubEO);
    }
}
